package com.sky.mapper;

import com.sky.entity.OrderDetail;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author yangkexuan
 * @className OrderDetailMapper
 * @date 2023/6/13 15:59
 * @description
 */
@Mapper
public interface OrderDetailMapper {
    /**
     * 明细表插入数据
     * @param orderDetailList
     */
    void insertBatch(List<OrderDetail> orderDetails);

    /**
     * 查询订单明细
     * @param ordersId
     * @return
     */
    @Select("select * from order_detail where order_id = #{ordersId}")
    List<OrderDetail> getByOrderId(Long ordersId);

    /**
     * 根据订单ID显示所有的菜品名称
     * @param id
     * @return
     */
    @Select("SELECT GROUP_CONCAT(CONCAT(st.name, '*', st.num) SEPARATOR ', ') AS orderDishes " +
            "FROM (select name, count(*)  num from order_detail where order_id = #{id} group by name) st")
    String getNameByOrderId(Long id);

}
